package com.fy56.platform.logistics.restful.api.controller.wx;

import com.alibaba.fastjson.JSON;
import com.fy56.platform.logistics.common.ResultModel;
import com.fy56.platform.logistics.common.ResultStatus;
import com.fy56.platform.logistics.model.ColumnExt;
import com.fy56.platform.logistics.model.Company;
import com.fy56.platform.logistics.restful.api.app.authorization.annotation.Authorization;
import com.fy56.platform.logistics.service.web.IColumnExtService;
import com.fy56.platform.logistics.service.wx.ICompanyInfoService;
import com.google.common.collect.Lists;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 字段扩展信息RestController
 * Created by sxg on 2018/8/7.
 */
@Api(value = "ColumnExt", description = "字段扩展信息", produces = MediaType.APPLICATION_JSON_VALUE)
@RestController
@RequestMapping("/columnExt")
public class ColumnExtController {

    @Autowired
    private IColumnExtService iColumnExtService;

    @Autowired
    private ICompanyInfoService iCompanyService;

    private static Logger log = Logger.getLogger(ColumnExtController.class);

    @RequestMapping(value = "/findColumnExtList", method = RequestMethod.POST)
    @ApiOperation(value = "根据页面获取字段扩展信息")
    @Authorization
    @ResponseBody
    public ResponseEntity findColumnExtList(@RequestParam String data) {

        List<ColumnExt> list = Lists.newArrayList();
        Map<String,Object> parameter = null;
        try{
            parameter = JSON.parseObject(data);
        }catch(Exception e){
            log.error("参数转换错误：",e);
            return new ResponseEntity(new ResultModel(100,"参数有误",null), HttpStatus.OK);
        }

        try {
            list = iColumnExtService.findColumnExtList(parameter);
            return new ResponseEntity(ResultModel.ok(list), HttpStatus.OK);
        } catch (Exception e) {
            log.error("获取字段扩展信息失败：" + data,e);
            return new ResponseEntity(ResultModel.error(ResultStatus.SERVER_ERROR, "获取字段扩展信息失败"), HttpStatus.OK);
        } finally {
            list = null;
        }
    }

}
